<div class="bg-light lter b-b wrapper-md">
  <h1 class="m-n font-thin h3">直播流管理</h1>
</div>



<div class="wrapper-md"  >
  <div class="panel panel-default">
    <div ng-controller="infoEditCtrl">
      <div class="row">

        <div class="col-sm-12" >
          <form name="form-contact" ng-submit="processForm()" class="form-horizontal">

            <div class="panel-heading">
              <span class="h4">

                <button class="btn btn-default btn-sm " ng-click="goBack()"><i class="fa fa-mail-reply fa-lg"></i>&nbsp; 返回</button>


              </span>
            </div>
            <div class="panel-body">
             <div class="panel-heading">
              <span class="h4" style="color:#2196f3;">直播流简介信息</span>
            </div>


            <div class="form-group">
              <label class="col-sm-1 control-label">流名称</label>
              <div class="col-sm-5">
               <input type="text" class="form-control" placeholder="流名称" ng-model="contact.StreamName" required >
             </div>



             <label  class="col-sm-1 control-label">传输模式</label>
             <div class="col-sm-5">
              <select class="form-control " ng-model="contact.SignalTransMode" required >
               <option ng-repeat="x in signalTransModes" value="{{x.key}}">{{x.value}}</option>
             </select>
           </div>
         </div>
         <div class="line line-dashed b-b line-lg pull-in"></div>

         <div class="form-group">
          <label class="col-sm-1 control-label">时移时间</label>
          <div class="col-sm-5">
           <input type="number" min="0" max="7" class="form-control" placeholder="时移天数" ng-model=" " >
         </div>

         <div class="line line-dashed b-b line-lg pull-in"></div>

         <div class="form-group">
           <label class="col-sm-1 control-label">备注</label>  
           <div class="col-sm-10">
             <textarea class="form-control" ng-model="contact.StreamRemark" rows="6" placeholder="备注"></textarea>
           </div>
         </div>
         <div class="line line-dashed b-b line-lg pull-in"></div>

         <div class="panel-body">

           <div class="panel-heading">
             <span class="h4" style="color:#2196f3;">配置信息</span>
           </div>



           <div class="form-group">
            <label class="col-sm-1 control-label">启用/停用</label>
            <div class="col-sm-1">
             <label class="i-switch m-t-xs m-r">
              <input type="checkbox" ng-model="StreamEnable"  checked>
              <i></i>
            </label>
          </div>


          <label class="col-sm-1 control-label">PC</label>
          <div class="col-sm-1">
           <label class="i-switch m-t-xs m-r">
            <input type="checkbox" ng-model="StreamDisplayOnPc"  checked>
            <i></i>
          </label>
        </div>
        <label class="col-sm-1 control-label">Phone</label>
        <div class="col-sm-1">
         <label class="i-switch m-t-xs m-r">
          <input type="checkbox" ng-model="StreamDisplayOnPhone"  checked>
          <i></i>
        </label>
      </div>


      <label class="col-sm-1 control-label">Pad</label>
      <div class="col-sm-1">
       <label class="i-switch m-t-xs m-r">
        <input type="checkbox"  ng-model="StreamDisplayOnPad"  checked>
        <i></i>
      </label>
    </div>

    <label class="col-sm-1 control-label">TV</label>
    <div class="col-sm-1">
     <label class="i-switch m-t-xs m-r">
      <input type="checkbox"  ng-model="StreamDisplayOnTv"  checked>
      <i></i>
    </label>
  </div>


</div>
<div class="line line-dashed b-b line-lg pull-in"></div>



<div class="form-group">
  <label class="col-sm-1 control-label">RTMP流</label>
  <div class="col-sm-1">
   <label class="i-switch m-t-xs m-r">
    <input type="checkbox" ng-model="OutputRtmp"  checked>
    <i></i>
  </label>
</div>


<label class="col-sm-1 control-label">RTSP流</label>
<div class="col-sm-1">
 <label class="i-switch m-t-xs m-r">
  <input type="checkbox" ng-model="OutputRtsp"  checked>
  <i></i>
</label>
</div>
<label class="col-sm-1 control-label">HTTP流</label>
<div class="col-sm-1">
 <label class="i-switch m-t-xs m-r">
  <input type="checkbox" ng-model="OutputHttp"  checked>
  <i></i>
</label>
</div>


<label class="col-sm-1 control-label">HLS流</label>
<div class="col-sm-1">
 <label class="i-switch m-t-xs m-r">
  <input type="checkbox"  ng-model="OutputHls"  checked>
  <i></i>
</label>
</div>

<label class="col-sm-1 control-label">UDP流</label>
<div class="col-sm-1">
 <label class="i-switch m-t-xs m-r">
  <input type="checkbox"  ng-model="OutputUdp"  checked>
  <i></i>
</label>
</div>


</div>
<div class="line line-dashed b-b line-lg pull-in"></div>






<!--隐藏字段-->
<input type="hidden"  ng-model="contact.Id"  >
<input type="hidden"  ng-model="contact.StreamUuid"  >
<input type="hidden"  ng-model="contact.AdderId"  >
<input type="hidden"  ng-model="contact.AdderName"  >
<input type="hidden"  ng-model="contact.AddTime"  >
<input type="hidden"  ng-model="contact.UpdaterId"  >
<input type="hidden"  ng-model="contact.UpdaterName"  >
<input type="hidden"  ng-model="contact.UpdateTime"  >
<input type="hidden"  ng-model="contact.DelFlag"  ng-init="contact.DelFlag='0'" >

<!--隐藏字段-->

</div>
<footer class="panel-footer text-right bg-light lter">
  <button type="submit" class="btn btn-success">提交</button>
</footer>
</div>
</form>
</div>
</div>

</div>
</div>




</div>


<!--angularjs-->
<script type="text/javascript">
  app.controller('infoEditCtrl', function ($scope, $state, $stateParams,$http,$window) {


    $scope.videoDars = [
    {key : "11：4", value : "11：4"},
    {site : "20:22", value : "20:22"},
    {key : "18:22", value : "18:22"}
    ];
    $scope.signalTransModes = [
    {key : "push", value : "推模式"},
    {key : "pull", value : "拉模式"}
    ];


    var getInfoUrl = API_URL+"server_info?query=delflag:0"    

    $scope.servers =  MY_ASYNC_AJAX(getInfoUrl);




//返回按钮：开始
$scope.$window = $window;
$scope.goBack = function() {
  $window.history.back();
};
//返回按钮：结束

var infoId = $stateParams.infoId;
console.log('获取路由参数infoId：'+infoId);


 //如果infoId不为空，查询详情：开始
 if(''!=infoId){
  var getInfoUrl = API_URL+"stream_info?query=delflag:0,id:"+infoId+"&sortby=updateTime&order=desc"

  $http.get(getInfoUrl).success(function (response) {

   var obj = response[0];

   obj.StreamDisplayOrder = Number(obj.StreamDisplayOrder);

   if("0" == obj.StreamDisplayOnPc){
     $scope.StreamDisplayOnPc = false;
   }
   if("0" == obj.StreamDisplayOnPhone){
    $scope.StreamDisplayOnPhone = false;
  }
  if("0" == obj.StreamDisplayOnPad){
   $scope.StreamDisplayOnPad = false;
 }
 if("0" == obj.StreamDisplayOnTv){
   $scope.StreamDisplayOnTv = false;
 }
 if("0" == obj.OutputRtmp){
   $scope.OutputRtmp = false;
 }
 if("0" == obj.OutputRtsp){
  $scope.OutputRtsp = false;
}
if("0" == obj.OutputHls){
 $scope.OutputHls = false;
}
if("0" == obj.OutputUdp){
 $scope.OutputUdp = false;
}

$scope.contact = obj;
});
}
//如果infoId不为空，查询详情：结束




  //表单提交开始
  $scope.processForm= function (){
  //1.参数处理

//发起POST请求
var postInfoUrl = API_URL+"stream_info";
var formData =  $scope.contact;

  //1.参数处理
  formData.AddTime = getNowDBFormatDate();
  formData.UpdateTime = getNowDBFormatDate();
  formData.StreamDisplayOrder=formData.StreamDisplayOrder + '';
  formData.AdderId = 1;
  formData.AdderName = '1';
  formData.UpdaterId = 1;
  formData.UpdaterName = '1';
  formData.SignalUuid='';


  if(false == $scope.StreamEnable){
    formData.StreamEnable = '1';
  }else {
     formData.StreamEnable = '0';
  }
  if(false == $scope.StreamDisplayOnPc){
    formData.StreamDisplayOnPc = '0';
  }else {
    formData.StreamDisplayOnPc = '1';
  }
  if(false == $scope.StreamDisplayOnPad){
    formData.StreamDisplayOnPad = '0';
  }else {
    formData.StreamDisplayOnPad = '1';
  }

  if(false == $scope.StreamDisplayOnPhone){
    formData.StreamDisplayOnPhone = '0';
  }else {
    formData.StreamDisplayOnPhone = '1';
  }
  if(false == $scope.StreamDisplayOnTv){
    formData.StreamDisplayOnTv = '0';
  }else {
     formData.StreamDisplayOnTv = '1';
  }

  if(false == $scope.OutputRtmp){
    formData.OutputRtmp = '0';
  }else {
     formData.OutputRtmp = '1';
  }
  if(false == $scope.OutputRtsp){
    formData.OutputRtsp = '0';
  }else {
    formData.OutputRtsp = '1';
  }

  if(false == $scope.OutputHls){
    formData.OutputHls = '0';
  }else {
     formData.OutputHls = '1';
  }
  if(false == $scope.OutputUdp){
    formData.OutputUdp = '0';
  }else {
     formData.OutputUdp = '1';
  }    



  if("undefined"!=typeof(formData.Id)){

    $.ajax( {  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'put', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl+'/'+infoId, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                    console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 

                    top.layer.msg('保存成功', {icon: 6});
                 //2.成功跳转页面
                 $state.go('app.stream.stream');
               }  
             }); 


  }else{

    $.ajax( {  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'post', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                    console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 

                    top.layer.msg('保存成功', {icon: 6});
                 //2.成功跳转页面
                 $state.go('app.stream.stream');
               }  
             }); 

  }
}
 //表单提交结束
 

});



// this is a lazy load controller, 
// so start with "app." to register this controller

app.filter('propsFilter', function() {
  return function(items, props) {
    var out = [];

    if (angular.isArray(items)) {
      items.forEach(function(item) {
        var itemMatches = false;

        var keys = Object.keys(props);
        for (var i = 0; i < keys.length; i++) {
          var prop = keys[i];
          var text = props[prop].toLowerCase();
          if (item[prop].toString().toLowerCase().indexOf(text) !== -1) {
            itemMatches = true;
            break;
          }
        }

        if (itemMatches) {
          out.push(item);
        }
      });
    } else {
          // Let the output be the input untouched
          out = items;
        }

        return out;
      };
    })





//选择类型下拉框
app.controller('SelectCtrl', function($scope, $http, $stateParams,$timeout) {



  $scope.disabled = undefined;
  $scope.searchEnabled = undefined;

  $scope.enable = function() {
    $scope.disabled = false;
  };

  $scope.disable = function() {
    $scope.disabled = true;
  };

  $scope.enableSearch = function() {
    $scope.searchEnabled = true;
  }

  $scope.disableSearch = function() {
    $scope.searchEnabled = false;
  }

  $scope.clear = function() {
    $scope.person.selected = undefined;
    $scope.address.selected = undefined;
    $scope.country.selected = undefined;
  };


  $scope.personAsync = {selected : "wladimir@email.com"};
  $scope.peopleAsync = [];


  $scope.counter = 0;
  $scope.someFunction = function (item, model){
    $scope.counter++;
    $scope.eventResult = {item: item, model: model};
  };

  $scope.removed = function (item, model) {
    $scope.lastRemoved = {
      item: item,
      model: model
    };
  };

  $scope.person = {};

  var infoUrl = API_URL+"stream_class?query=delflag:0";

  var formData =  MY_ASYNC_AJAX(infoUrl);
  $scope.people = formData;
  $scope.multipleDemo = {};
  $scope.multipleDemo.colors = ['Blue','Red'];

        //已经存在的
        var infoId = $stateParams.infoId;
        $scope.multipleDemo.selectedPeopleWithGroupBy = [];

        if(''!=infoId){
          var classUrl = API_URL+"r_stream_2_class?query=delflag:0,StreamId:"+infoId;
          var classList = MY_ASYNC_AJAX(classUrl);
          console.log('获取classList：'+classList);
          if(null !=  classList){
            for(var i= 0;i<classList.length;i++){
             var infoClassUrl = API_URL+"stream_class?query=delflag:0,Id:"+classList[i].ClassId;
             var infoClass = MY_ASYNC_AJAX(infoClassUrl)[0];
             for(var j=0;j<formData.length;j++){
              if($scope.people[j].Id == infoClass.Id){
                $scope.multipleDemo.selectedPeopleWithGroupBy.push($scope.people[j]);
                break;
              }
            }

          }
        }
      }



      
    });



  </script>
  <!--angularjs-->










